"use strict";
const common_vendor = require("../../common/vendor.js");
const __unplugin_components_2 = () => "../../node-modules/wot-design-uni/components/wd-button/wd-button.js";
const __unplugin_components_1 = () => "../../node-modules/wot-design-uni/components/wd-loading/wd-loading.js";
const __unplugin_components_0 = () => "../../node-modules/wot-design-uni/components/wd-icon/wd-icon.js";
if (!Array) {
  const _component_wd_icon = __unplugin_components_0;
  const _component_wd_loading = __unplugin_components_1;
  const _component_wd_button = __unplugin_components_2;
  const _component_layout_default_uni = common_vendor.resolveComponent("layout-default-uni");
  (_component_wd_icon + _component_wd_loading + _component_wd_button + _component_layout_default_uni)();
}
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "result",
  setup(__props) {
    const calorieResult = common_vendor.ref({
      foodName: "经典蛋挞",
      foodType: "烘焙甜点",
      calorie: 200,
      servingSize: "单个(约80克)",
      confidence: "95%",
      nutrients: [
        { name: "蛋白质", value: "4", unit: "克" },
        { name: "脂肪", value: "12", unit: "克" },
        { name: "碳水化合物", value: "18", unit: "克" },
        { name: "膳食纤维", value: "0.5", unit: "克" },
        { name: "糖", value: "10", unit: "克" }
      ],
      macronutrientRatio: {
        proteinPercentage: "8%",
        fatPercentage: "54%",
        carbsPercentage: "38%"
      },
      keyIngredients: ["鸡蛋", "牛奶", "面粉", "糖", "黄油"],
      nutritionalEvaluation: {
        energyDensity: "高",
        nutrientBalance: "脂肪和碳水化合物含量较高，蛋白质适中，膳食纤维不足",
        healthImpact: "含有较高的饱和脂肪和添加糖，过量摄入可能增加肥胖风险"
      },
      dietAdvice: {
        summary: "蛋挞属于高热量、高脂肪的甜点，建议适量食用，可搭配低热量食物平衡膳食",
        portionControl: "建议每次食用不超过1个，每周不超过2次",
        mealTiming: "可作为早餐或下午茶的小点心，但避免在晚餐后食用",
        suitableFor: "需要补充能量的人群、偶尔作为奖励的健康人士",
        notSuitableFor: "糖尿病患者、高血脂患者、减肥人群、心血管疾病患者",
        pairingSuggestions: ["搭配无糖茶或黑咖啡帮助消化", "搭配新鲜水果增加膳食纤维摄入"]
      },
      imageUrl: "/static/food-sample.jpg"
    });
    const loading = common_vendor.ref(true);
    const error = common_vendor.ref(null);
    const pageResult = common_vendor.ref(null);
    
    // 在onLoad中获取页面参数
    common_vendor.onLoad((options) => {
      if (options.result) {
        pageResult.value = options.result;
      }
    });
    
    common_vendor.onMounted(() => {
      try {
        const analysisResult = pageResult.value;
        if (analysisResult) {
          const decodedResult = decodeURIComponent(analysisResult);
          const parsedResult = JSON.parse(decodedResult);
          if (parsedResult.choices && parsedResult.choices[0] && parsedResult.choices[0].message && parsedResult.choices[0].message.content) {
            try {
              const aiContent = JSON.parse(parsedResult.choices[0].message.content);
              calorieResult.value = {
                ...aiContent,
                imageUrl: "/static/food-sample.jpg"
              };
            } catch (e) {
              console.error("解析AI内容失败:", e);
              error.value = "解析分析结果失败";
            }
          } else {
            error.value = "未找到有效分析结果";
          }
        } else {
          console.log("使用默认模拟数据");
        }
      } catch (e) {
        error.value = "解析分析结果失败";
        console.error("解析分析结果失败:", e);
      } finally {
        loading.value = false;
      }
    });
    function navigateBack() {
      common_vendor.index.switchTab({
        url: "/pages/index/index"
      });
    }
    function reAnalyze() {
      common_vendor.index.navigateBack();
    }
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.p({
          name: "arrow-left",
          size: "20px",
          color: "#fff"
        }),
        b: common_vendor.o(navigateBack),
        c: loading.value
      }, loading.value ? {
        d: common_vendor.p({
          type: "ring",
          size: "40px",
          color: "#FF7D00"
        })
      } : error.value ? {
        f: common_vendor.p({
          name: "warning-circle",
          size: "60px",
          color: "#FF7D00"
        }),
        g: common_vendor.t(error.value),
        h: common_vendor.o(reAnalyze),
        i: common_vendor.p({
          type: "primary"
        })
      } : calorieResult.value ? {
        k: common_vendor.t(calorieResult.value.foodName),
        l: common_vendor.t(calorieResult.value.foodType),
        m: common_vendor.t(calorieResult.value.calorie),
        n: common_vendor.t(calorieResult.value.servingSize),
        o: common_vendor.t(calorieResult.value.confidence),
        p: common_vendor.f(calorieResult.value.nutrients, (nutrient, index, i0) => {
          return {
            a: common_vendor.t(nutrient.name),
            b: common_vendor.t(nutrient.value),
            c: common_vendor.t(nutrient.unit),
            d: index
          };
        }),
        q: common_vendor.t(calorieResult.value.macronutrientRatio.proteinPercentage),
        r: common_vendor.t(calorieResult.value.macronutrientRatio.fatPercentage),
        s: common_vendor.t(calorieResult.value.macronutrientRatio.carbsPercentage),
        t: common_vendor.f(calorieResult.value.keyIngredients, (ingredient, index, i0) => {
          return {
            a: "f21d35ee-5-" + i0 + ",f21d35ee-0",
            b: common_vendor.t(ingredient),
            c: index
          };
        }),
        v: common_vendor.p({
          name: "check-circle",
          size: "24rpx",
          color: "#4CAF50"
        }),
        w: common_vendor.p({
          name: "clipboard-list",
          size: "18px",
          color: "#4CAF50"
        }),
        x: common_vendor.t(calorieResult.value.nutritionalEvaluation.energyDensity),
        y: common_vendor.t(calorieResult.value.nutritionalEvaluation.nutrientBalance),
        z: common_vendor.t(calorieResult.value.nutritionalEvaluation.healthImpact),
        A: common_vendor.p({
          name: "knife-fork",
          size: "18px",
          color: "#FFAB00"
        }),
        B: common_vendor.t(calorieResult.value.dietAdvice.summary),
        C: common_vendor.t(calorieResult.value.dietAdvice.portionControl),
        D: common_vendor.t(calorieResult.value.dietAdvice.mealTiming),
        E: common_vendor.t(calorieResult.value.dietAdvice.suitableFor),
        F: common_vendor.t(calorieResult.value.dietAdvice.notSuitableFor),
        G: common_vendor.p({
          name: "utensils",
          size: "24rpx",
          color: "#2196F3"
        }),
        H: common_vendor.f(calorieResult.value.dietAdvice.pairingSuggestions, (suggestion, index, i0) => {
          return {
            a: common_vendor.t(index + 1),
            b: common_vendor.t(suggestion),
            c: index
          };
        }),
        I: common_vendor.o(reAnalyze),
        J: common_vendor.p({
          type: "primary"
        }),
        K: common_vendor.o(navigateBack),
        L: common_vendor.p({
          type: "default"
        })
      } : {}, {
        e: error.value,
        j: calorieResult.value
      });
    };
  }
});
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-f21d35ee"]]);
wx.createPage(MiniProgramPage);
